package org.jason.model.common.dtos;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import org.jason.model.common.enums.HttpCodeEnum;

import java.io.Serializable;

@Getter
@ApiModel("默认相应模板")
public class ResponseResult<T> implements Serializable {
    @ApiModelProperty("状态码")
    private Integer code;
    @ApiModelProperty("提示")
    private String msg;
    @ApiModelProperty("数据对象")
    private T data;

    public ResponseResult() {
        this.code = 200;
    }

    public ResponseResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResponseResult(HttpCodeEnum httpCodeEnum, String msg) {
        this.code = httpCodeEnum.getCode();
        this.msg = msg;
    }

    public ResponseResult(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ResponseResult(HttpCodeEnum httpCodeEnum, String msg, T data) {
        this.code = httpCodeEnum.getCode();
        this.msg = msg;
        this.data = data;
    }

    public ResponseResult(HttpCodeEnum httpCodeEnum, T data) {
        this.code = httpCodeEnum.getCode();
        this.msg = httpCodeEnum.getMsg();
        this.data = data;
    }

    public ResponseResult(HttpCodeEnum httpCodeEnum) {
        this.code=httpCodeEnum.getCode();
        this.msg=httpCodeEnum.getMsg();
    }

    public static ResponseResult<?> get() {
        ResponseResult<Object> responseResult = new ResponseResult<>();
        responseResult.setHttpCodeEnum(HttpCodeEnum.SUCCESS);
        return responseResult;
    }

    public static ResponseResult<?> get(HttpCodeEnum httpCodeEnum) {
        ResponseResult<Object> responseResult = new ResponseResult<>();
        responseResult.setHttpCodeEnum(httpCodeEnum);
        return responseResult;
    }

    public static ResponseResult<?> get(HttpCodeEnum httpCodeEnum, String msg) {
        ResponseResult<Object> responseResult = new ResponseResult<>();
        responseResult.code = httpCodeEnum.getCode();
        responseResult.msg = msg;
        return responseResult;
    }

    public ResponseResult<?> get(HttpCodeEnum httpCodeEnum, String msg, T data) {
        ResponseResult<Object> responseResult = new ResponseResult<>();
        responseResult.code = httpCodeEnum.getCode();
        responseResult.msg = msg;
        responseResult.data = data;
        return responseResult;
    }

    public ResponseResult<T> get(HttpCodeEnum httpCodeEnum, T data) {
        ResponseResult<T> responseResult = new ResponseResult<>();
        responseResult.setHttpCodeEnum(httpCodeEnum);
        responseResult.data = data;
        return responseResult;
    }

    private void setHttpCodeEnum(HttpCodeEnum httpCodeEnum) {
        this.code = httpCodeEnum.getCode();
        this.msg = httpCodeEnum.getMsg();
    }
}
